import {
  Body,
  Controller,
  Delete,
  Get,
  Param, ParseUUIDPipe,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
  CarouselAdminCreateDto,
  CarouselAdminIndexDto,
  CarouselAdminUpdateDto,
} from './carousel.dto';
import { CarouselService } from './carousel.service';
import { AdminAuthGuard } from "@/common/auth/admin-auth.guard";
import { getPager } from "@/common/pager-response";
import { CarouselAdminIndexResult, CarouselAllResult } from "@/module/carousel/carousel.result";
import { PageResult } from "common/interface";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";

@Controller('/v1/admin/carousels')
@ApiTags('Carousel_admin')
@UseGuards(AdminAuthGuard)
export class CarouselV1AdminController {
  constructor(private readonly carouselService: CarouselService) {
  }

  @Get('/')
  @ApiOperation({ summary: '列表查询' })
  @ApiPaginatedOkResponse(CarouselAdminIndexResult)
  async index(@Query() query: CarouselAdminIndexDto): Promise<PageResult<CarouselAdminIndexResult>> {
    const res = await this.carouselService.adminIndex(query);
    return getPager(res[0], res[1]);
  }

  @Post('/')
  @ApiOperation({ summary: '新增' })
  async create(@Body() body: CarouselAdminCreateDto): Promise<void> {
    await this.carouselService.adminCreate(body);
    return;
  }

  @Patch('/:uuid')
  @ApiOperation({ summary: '修改' })
  async update(
    @Body() body: CarouselAdminUpdateDto,
    @Param('uuid', ParseUUIDPipe) uuid: string,
  ): Promise<void> {
    await this.carouselService.adminUpdate(body, uuid);
    return;
  }

  @Delete('/:uuid')
  @ApiOperation({ summary: '删除' })
  async destroy(@Param('uuid', ParseUUIDPipe) uuid: string): Promise<void> {
    await this.carouselService.adminDestroy(uuid);
    return;
  }
}
